<?php
/**
 * User: @lixu
 * 同步wiki数据脚本
 * Date: 2019-05-14
 * Time: 15:33
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\esSearch\Wiki;
use Biz\model\wiki\Wiki as mWiki;
use Biz\model\wiki\WikiContent as mWikiContent;

// 同步wiki表数据至es

$wikiInfo = mWiki::select('*');

$wikiIds = array_column($wikiInfo, 'id');

$wikiContent = mWikiContent::select('*', ['wiki_id' => $wikiIds]);

$wikiContent = array_column($wikiContent, null, 'wiki_id');

foreach ($wikiInfo as $value) {
    if(isset($wikiContent[$value['id']])) {
        $value['imgs'] = $wikiContent[$value['id']]['imgs'];
        $value['content'] = $wikiContent[$value['id']]['content'];
    }
    $result = Wiki::saveByWikiId($value);
    var_dump($result);
}

